import React from 'react';

import BaseAction from '../common/BaseAction';
import Constants from '../../common/Constants';
import ResponseConstants from '../../common/ResponseConstants';

export default class LoginSendRegisteAction extends BaseAction {
  constructor() {
    super();

    this.moduleType = Constants.MODULE_TYPE.LOGIN;
    this.name = "LoginSendRegisteAction";
  }

  call(caller, data) {
    this._baseCall(caller, data);
    this.caller.setState({
      viewStatus: 4,
    })
  }

  finish(data, isSucceed, response) {
    var authorization = 0;
    var detail = "";
    if(isSucceed) {
      if(response.status == ResponseConstants.status_conflict) {
        detail = "您已注册过，请直接去登录";
      }
      else if(response.status == ResponseConstants.status_created_success) {
        detail = "注册成功";
        authorization = response.headers.map.authorization[0]
      }
      else if(response.status == ResponseConstants.status_unauthorized) {
        detail = data.detail;
      }
    }
    this.caller.setState({
      viewStatus: response.status,
      statusText:detail,
      authorization: authorization,
      userData:this.data,
    });
  }
}
